<template>
  <div>
  <a-card :bordered="false">
    <!-- 查询区域 -->
    <div class="table-page-search-wrapper">
      <a-form layout="inline" @keyup.enter.native="searchQuery">
        <a-row :gutter="24">
          <a-col :md="6" :sm="12">
            <a-form-item label="表名称">
              <j-input
                placeholder="输入表名称"
                v-model="queryParam.tableName"
              ></j-input>
            </a-form-item>
          </a-col>

          <a-col :md="6" :sm="12">
            <a-form-item label="表描述">
                <j-input
                    placeholder="输入表描述"
                    v-model="queryParam.tableDesc"
                ></j-input>
            </a-form-item>
          </a-col>

          <a-col :md="6" :sm="8">
            <span style="float: left; overflow: hidden" class="table-page-search-submitButtons">
              <a-button type="primary" @click="searchQuery" icon="search">查询</a-button>
              <a-button type="" @click="searchReset" icon="reload" style="margin-left: 8px">重置</a-button>
            </span>
          </a-col>
        </a-row>
      </a-form>
    </div>
  </a-card>
  <a-card :bordered="false" style="margin-top: 10px">
  <!-- 操作按钮区域 -->
    <div class="table-operator" style="border-top: 5px;">
      <a-button @click="handleAdd" type="primary" icon="plus"
        >新增表</a-button
      >
      <a-dropdown v-if="selectedRowKeys.length > 0">
        <a-menu slot="overlay" @click="handleMenuClick">
          <a-menu-item key="1">
            <a-icon type="delete" @click="batchDel" />
            删除
          </a-menu-item>
        </a-menu>
        <a-button style="margin-left: 8px">
          批量操作
          <a-icon type="down" />
        </a-button>
      </a-dropdown>
    </div>

    <!-- table区域-begin -->
    <div>
      <div class="ant-alert ant-alert-info" style="margin-bottom: 16px">
        <i class="anticon anticon-info-circle ant-alert-icon"></i>已选择&nbsp;<a
          style="font-weight: 600"
          >{{ selectedRowKeys.length }}</a
        >项&nbsp;&nbsp;
        <a style="margin-left: 24px" @click="onClearSelected">清空</a>
      </div>

      <a-table
        ref="table"
        bordered
        rowKey="id"
        :columns="columns"
        :dataSource="dataSource"
        :pagination="ipagination"
        :loading="loading"
        :rowSelection="{
          selectedRowKeys: selectedRowKeys,
          onChange: onSelectChange,
        }"
        @change="handleTableChange"
      >
        <span slot="action" slot-scope="text, record">
          <a @click="handleEdit(record)">编辑</a>
          <a-divider type="vertical" />
          <a-dropdown>
            <a class="ant-dropdown-link"> 更多 <a-icon type="down"/> </a>
            <a-menu slot="overlay">
              <a-menu-item>
                <a href="javascript:;" @click="handleDetail(record)">功能测试</a>
              </a-menu-item>
              <a-menu-item>
                <a href="javascript:;" @click="handleDetail(record)">详情</a>
              </a-menu-item>
              <a-menu-item>
                  <a-popconfirm title="确定生成表吗?将会覆盖原有表" @confirm="() => handleCreate(record.id)">
                      <a>生成表</a>
                  </a-popconfirm>
              </a-menu-item>
              <a-menu-item>
                <a-popconfirm title="确定删除吗?" @confirm="() => handleDelete(record.id)">
                  <a>删除</a>
                </a-popconfirm>
              </a-menu-item>
            </a-menu>
          </a-dropdown>
        </span>
      </a-table>
    </div>
      <!-- table区域-end -->
      <table-modal ref="modalForm" @ok="modalFormOk"></table-modal>
  </a-card>
  </div>
</template>
<script>
import { getFileAccessHttpUrl } from "@/api/manage";
import { KsListMixin } from '@/mixins/KsListMixin'
import JInput from "@/components/ksource/JInput";
import {request, METHOD, removeAuthorization} from '@/utils/request'
import {createBpmTable} from '@/api/api'
import TableModal from "./modules/TableModal";

export default {
  name: "TableList",
  mixins: [KsListMixin],
  components: {
      TableModal,
      JInput
  },
  data() {
    return {
    formId:0,
      description: "自定义表管理页面",
            currentDeptId: '',
      queryParam: {},
      recycleBinVisible: false,
      columns: [
          {
              title: '表名称',
              align: "center",
              dataIndex: 'tableName',
              width: 120
          },
          {
              title: '表描述',
              align: "center",
              dataIndex: 'tableDesc',
              width: 120
          },

          {
              title: '表类型',
              align: "center",
              width: 100,
              dataIndex: 'type'
          },
          {
              title: '生成状态',
              align: "center",
              width: 100,
              dataIndex: 'createState',
              sorter: true,
              customRender: (text) => {
                  switch (text) {
                      case 1:
                          return "已生成";
                      default:
                          return "未生成";
                  }
              }
          },
          {
              title: '操作',
              dataIndex: 'action',
              scopedSlots: {customRender: 'action'},
              align: "center",
              width: 170
          }
      ],
      url: {
          list: "/base/bpm/table/list",
          delete: "/base/bpm/table/delete",
          deleteBatch: "/base/bpm/table/deleteBatch",
      },
    };
  },
  methods: {
    handleMenuClick(e) {
      if (e.key == 1) {
        this.batchDel();
      }
    },
      handleCreate(id){
          var that = this;
          createBpmTable({
              id: id
          }).then((res) => {
            if (res.success) {
              that.$message.success(res.message);
              that.loadData();
            } else {
              that.$message.warning(res.message);
            }
          })
      },
      handleAdd: function () {
          console.log("自定义新增")
          let screenWidth = document.body.clientWidth;
          let drawerWidth = screenWidth-200;
          this.$refs.modalForm.add();
          this.$refs.modalForm.title = "新增";
          this.$refs.modalForm.disableSubmit = false;
          this.$refs.modalForm.drawerWidth=drawerWidth;
      },
      handleEdit: function (record) {
          console.log("自定义编辑")
          let screenWidth = document.body.clientWidth;
          let drawerWidth = screenWidth-200;
          this.$refs.modalForm.edit(record);
          this.$refs.modalForm.title = "编辑";
          this.$refs.modalForm.disableSubmit = false;
          this.$refs.modalForm.drawerWidth=drawerWidth;
      },
      handleDetail: function (record) {
          console.log("自定义详情")
          let screenWidth = document.body.clientWidth;
          let drawerWidth = screenWidth-200;
          this.$refs.modalForm.edit(record);
          this.$refs.modalForm.title = "编辑";
          this.$refs.modalForm.disableSubmit = false;
          this.$refs.modalForm.drawerWidth=drawerWidth;
      },
  },
};
</script>
